

extension StringExtend on String {

  /// 分割
  String sub({int start=0 ,int? end}){
    end = end ?? length;
    if(end > length) end = length;
    return substring(0, end);
  }

  /// append
  String append(String text, {bool Function(String str)? predicate}){
    if(predicate?.call(this) != true){
      return this;
    }
    return this + text;
  }

  String ellipsis(int limit, {String suffix="...", bool including=false}){
    if(length <= limit){
      return this;
    }
    return sub(end: including?limit-suffix.length:limit) + suffix;
  }

}


extension ListExtend<T> on List<T> {

  Map<K,V>  toMap<K,V>(K Function(T item) key, V Function(T item) value){
      Map<K,V> result = {};
      for (var item in this) {
        var k = key.call(item);
        var v = value.call(item);
        result[k] = v;
      }
      return result;
  }

}